#!/bin/bash
#
DEFAULT_SOURCE_DIR="/home /root"
DEFAULT_TARGET_DIR="/backup"
DEFAULT_COMPRESS_KEEP_BACKUPS=0
DEFAULT_LOG_FILENAME="eloy.log"

CONFIG_FILE="$HOME/.eloy"

echo "
Copyright (c) 2007-2010 Maximilian Antoni. All rights reserved.

This software is licensed as described in the file LICENSE.txt, which you
should have received as part of this distribution. The terms are also
available at http://eloy.googlecode.com/svn/trunk/LICENSE.txt.


This script will generate an Eloy configuration file at $CONFIG_FILE.
Hit enter to continue."
read
echo -n "
The directories to back up. Speparate each entry by space. The given
directories will be saved recursively.
$DEFAULT_SOURCE_DIR: "
read SOURCE_DIR
: ${SOURCE_DIR:=$DEFAULT_SOURCE_DIR}

echo -n "
Optional excludes. Separate each entry by space. Entries starting with a
path from the SOURCE_DIR list are only applied to that path.
The part of the exclude after the source path is passed on to rsync.
Wildcards do work:
   * matches anything and stops at a slash
   ** does not stop at a slash
An example:
   SOURCE_DIR: /foo /bar
   EXCLUDE: /foo/*.tar.gz /bar/baz/**
All .tar.gz files in /foo are ignored, and all files and directories in
/bar/baz are ignored.
: "
read EXCLUDE
: ${EXCLUDE:=""}

echo -n "
The backup target directory. Make sure this directory is not part of the
SOURCE_DIR list.
$DEFAULT_TARGET_DIR: "
read TARGET_DIR
: ${TARGET_DIR:=$DEFAULT_TARGET_DIR}

echo -n "
How many daily backups to keep. 0 means all backups. Hourly backups will not
be included in the backup count. If there are more daily backups than the
specified number, Eloy deletes older backups when running the compress
subcommand.
$DEFAULT_COMPRESS_KEEP_BACKUPS: "
read COMPRESS_KEEP_BACKUPS
: ${COMPRESS_KEEP_BACKUPS:=0}

echo -n "
Log filename to use if the backup or compress subcommand is given the -l
option.
$TARGET_DIR/$DEFAULT_LOG_FILENAME: "
read LOG_FILENAME
: ${LOG_FILENAME:=$TARGET_DIR/$DEFAULT_LOG_FILENAME}

echo -n "
Plugins to use. Speparate each entry by space. Plugins are shell scripts
named eloy_<plugin>.sh. They are invoked at the beginning of the backup
sub command.
: "
read PLUGINS
: ${PLUGINS:=""}

touch $CONFIG_FILE
echo -n '#
#	Eloy backup system configuration file.
#
#	Copyright (c) 2007-2010 Maximilian Antoni. All rights reserved.
#
#	This software is licensed as described in the file LICENSE.txt, which you
#	should have received as part of this distribution. The terms are also
#	available at http://eloy.googlecode.com/svn/trunk/LICENSE.txt.
#

# The directories to back up. Speparate each entry by newline. The given
# directories will be saved recursively.
# 
SOURCE_DIR="' >> $CONFIG_FILE
echo -n $SOURCE_DIR | tr -s ' ' '\n' >> $CONFIG_FILE
echo -n '"

# Optional excludes. Separate each entry by newline. Entries starting with a
# path from the SOURCE_DIR list are only applied to that path.
# The part of the exclude after the source path is passed on to rsync.
# Wildcards do work:
#    "*" matches anything and stops at a slash
#    "**" does not stop at a slash
#
# An example:
#
#    SOURCE_DIR="/foo
#    /bar"
#    EXCLUDE="/foo/*.tar.gz
#    /bar/baz/**"
#
# All .tar.gz files in /foo are ignored, and all files and directories in
# /bar/baz are ignored.
#
EXCLUDE="' >> $CONFIG_FILE
echo -n $EXCLUDE | tr -s ' ' '\n' >> $CONFIG_FILE
echo -n '"

# The backup target directory. Make sure this directory is not part of the
# SOURCE_DIR list.
#
TARGET_DIR="'$TARGET_DIR'"

# How many daily backups to keep. 0 means all backups. Hourly backups will not
# be included in the backup count. If there are more daily backups than the
# specified number, Eloy deletes older backups when running the compress
# subcommand.
#
COMPRESS_KEEP_BACKUPS='$COMPRESS_KEEP_BACKUPS'

# Log filename to use if the backup or compress subcommand is given the -l
# option.
#
LOG_FILENAME="'$LOG_FILENAME'"

# Plugins to use. Plugins are shell scripts named "eloy_<plugin>.sh".
# They are invoked at the beginning of the backup sub command.
#
PLUGINS="' >> $CONFIG_FILE
echo -n $PLUGINS | tr -s ' ' '\n' >> $CONFIG_FILE
echo '"
' >> $HOME/.eloy
